<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户列表</title>
    <style>
        table,tr,td {
            border: 1px solid;
        }
    </style>
</head>
<script src="{{asset('js/jquery.js')}}"></script>
<script src="{{asset('js/layer/layer.js')}}"></script>
<body>
    <table>
        <tr>
            <td>ID</td>
            <td>用户名</td>
            <td>密码</td>
            <td>操作</td>
        </tr>
        @foreach($user as $v)
        <tr>
            <td>{{$v->id}}</td>
            <td>{{$v->username}}</td>
            <td>{{$v->password}}</td>
            <td><a href="{{url('user/edit')}}/{{$v->id}}">修改</a>|<a onclick="del({{$v->id}})" href="javascript:;">删除</a></td>
        </tr>
        @endforeach
    </table>
</body>
<script>
    // 删除
    function del(id){
        console.log(id);
        layer.confirm('确定要删除吗？', {
            btn: ['确定','取消']
        }, function(){
            $.post('{{url("user/del")}}',{'_token':'{{csrf_token()}}','id':id},function(res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                }else{
                    layer.msg(res.msg);
                    setTimeout(function(){window.location.reload();},1000);
                }
            },'json');
        });
    }
</script>
</html>